package me.zynaga.ragecraft;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Ragecraft extends JavaPlugin {

    public String settingsName = "settings.yml";
    public String pluginPath = "./plugins/";
    public PluginDescriptionFile pdf = null;
    public Database db = null;
    public Settings settings = null;
    public Commands cmds = null;
    public ArrayList<Player> gods = new ArrayList<Player>();
    public static final Logger log = Logger.getLogger("Minecraft");
    /*
    public static void main(String[] args) {
    //DO NOTHING
    }
    /**/

    public void log(String message) {

        log(message, Level.INFO);

    }

    public void log(String message, Level level) {

        log.log(level, "[" + pdf.getName() + "] " + message);

    }

    @Override
    public void onEnable() {

        pdf = this.getDescription();

        try {

            pluginPath = this.getDataFolder().getPath() + "\\";

            settings = new Settings(this);

            db = new Database(this);

            if (db.isReady == true && settings.isReady == true) {

                log("v" + pdf.getVersion() + " is enabled!");

            } else {

                this.getServer().getPluginManager().disablePlugin(this);

            }

            cmds = new Commands(this);

        } catch (Exception e) {

            this.getServer().getPluginManager().disablePlugin(this);

            log("Couldn't create directories, settings or database file(s).", Level.SEVERE);

        }

    }

    @Override
    public void onDisable() {

        log("is disabled!");

    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {

        return cmds.send(CommandLabel, args, sender);

    }
}